layui.define(['form'],function (exports) {
    var $ = layui.$,
        form = layui.form,
        layer = layui.layer;
    var href=location.href;

    var login = {
        init:function(){

            if (href.indexOf("kickout")>1){
                login.kickout();
            }
            //超时
            login.overtime();
        },
        //提示
        kickout: function () {
        layer.alert("<font color='red'>此账户已在其他设备上登录，请您修改密码或重新登录</font>", {
                icon: 0,
                closeBtn: 0,
                title: "系统提示"
            },
            function (index) {
                //关闭弹窗
                layer.close(index);
                if (top != self) {
                    top.location = self.location;
                } else {
                    var url = location.search;
                    if (url) {
                        var oldUrl = window.location.href;
                        var newUrl = oldUrl.substring(0, oldUrl.indexOf('?'));
                        self.location = newUrl;
                    }
                }
            });
        },
        //提示错误信息
        message: function (msg) {
            if (msg != null && msg != "") {

                layer.msg(msg, {
                    icon: 5,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                }, function () {
                });

            }
        },
        //登录超时
        overtime:function () {
            if(top.location.href != self.location.href){
                layer.alert("登录超时，请重新登录!",{
                    closeBtn: 0,
                    icon: 5,//图标类型
                    anim: 2//动画类型
                },function(){
                    top.location.href=self.location.href;
                });
            }

        }

    };
    exports('login', login);
});

